package com.dingup.paike.controller.log;

import com.dingup.api.Util.DateUtil;
import com.dingup.api.base.HttpResContent;
import com.dingup.api.bean.feign.log.LogSearchFeignBean;
import com.dingup.api.enums.log.LogModelEnum;
import com.dingup.api.enums.log.LogUpdateTypeEnum;
import com.dingup.api.model.sys.SysLog;
import com.dingup.paike.adapter.pk.PkLessonInfoAdapter;
import com.dingup.paike.feign.client.log.LogFeignClient;
import com.dingup.paike.service.pk.LogService;
import com.dingup.paike.service.pk.impl.LogServiceImpl;
import com.suyeer.basic.util.BHttpResUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Arrays;
import java.util.List;

import static com.dingup.api.base.BaseUtil.saveErrorMsgAndData;
import static com.dingup.api.base.BaseUtil.saveSuccessMsgAndData;

/**
 * Created by wancheng on 2018/10/13.
 */
@Controller
@RequestMapping("/log")
public class LogController {

    private static Logger logger = LoggerFactory.getLogger(LogController.class);

    @Autowired
    LogService logService;

    @RequestMapping(value = "/get_pk_lesson_log_by_id.do", method = RequestMethod.POST)
    public void getLog(HttpServletRequest request,
                       HttpServletResponse response,
                       Integer id) {
        HttpResContent<List<SysLog>> hrc = new HttpResContent<>(request, response);
        hrc.setFuncDes("获取排课日志,id:"+id);
        try {
            LogUpdateTypeEnum[] type = {LogUpdateTypeEnum.ADD,LogUpdateTypeEnum.UPDATE,LogUpdateTypeEnum.UPDATE_ADD,LogUpdateTypeEnum.UPDATE_DELETE,LogUpdateTypeEnum.UPDATE_STATUS};
            Integer[] modelId = {id};
            LogModelEnum[] model = {LogModelEnum.PKLESSONINFO};

            LogSearchFeignBean bean = new LogSearchFeignBean();
            bean.setModelId(Arrays.asList(modelId));
            bean.setModel(Arrays.asList(model));
            bean.setUpdateType(Arrays.asList(type));
            List<SysLog> logs = logService.getLog(bean);

            saveSuccessMsgAndData(hrc, logs);
        } catch (Exception e) {
            saveErrorMsgAndData(hrc, e);
        } finally {
            BHttpResUtil.writeResult(hrc, true);
        }
    }

    @RequestMapping(value = "/get_pk_lesson_log.do",method = RequestMethod.POST)
    public void getLog(HttpServletRequest request, HttpServletResponse response
    ) {
        HttpResContent<List<SysLog>> hrc = new HttpResContent<>(request, response);
        hrc.setFuncDes("获取所有排课日志");
        try {
            LogUpdateTypeEnum[] type = {LogUpdateTypeEnum.ADD,LogUpdateTypeEnum.DELETE};
            LogModelEnum[] model = {LogModelEnum.PKLESSONINFO};
            LogSearchFeignBean bean = new LogSearchFeignBean();
            bean.setModel(Arrays.asList(model));
            bean.setUpdateType(Arrays.asList(type));
            List<SysLog> logs = logService.getLog(bean);

            saveSuccessMsgAndData(hrc, logs);
        } catch (Exception e) {
            saveErrorMsgAndData(hrc, e);
        } finally {
            BHttpResUtil.writeResult(hrc, true);
        }
    }
}
